import React from "react";
import {inject, observer} from "mobx-react";
import {withRouter} from "react-router-dom";
import {Accordion, Icon, InputItem, List, Select, Tools} from "weaver-mobile";
import {Browser, BrowserHrm, RouteLayout} from "weaver-mobile-page";
import {observable} from "mobx";

const getLabel = Tools.getLabel;
const ButtonGroup = RouteLayout.ButtonGroup;
const cicleData = [
    {key: "", showname: ""},
    {key: "1", showname: getLabel(19398, "月度")},
    {key: "2", showname: getLabel(17495, "季度")},
    {key: "3", showname: getLabel(20729, "半年")},
    {key: "4", showname: getLabel(17138, "年度")},
];
const includesubData = [
    {key: "3", showname: getLabel(508780, "含子分部")},
    {key: "1", showname: getLabel(18919, "仅本分部")},
    {key: "2", showname: getLabel(18920, "仅子分部")},
];
const includedeptData = [
    {key: "3", showname: getLabel(508784, "含子部门")},
    {key: "1", showname: getLabel(18916, "仅本部门")},
    {key: "2", showname: getLabel(18917, "仅子部门")},
];

/**
 * 待审核方案
 * jiansong 2019/11/8
 */
@inject("accessAuditStore")
@withRouter
@observer
export default class Condition extends React.Component {

    constructor(props) {
        super(props);
        this.store = this.props.accessAuditStore;
    }

    render() {
        const {queryParams, subBrowser, deptBrowser, subBrowserValue, deptBrowserValue, setState, onSearchChange, hrmBrowser, hrmBrowserValue} = this.store;
        return (
            <div className="wm-route-layout workrelate-condition">
                <Accordion defaultActiveKey="0">
                    <Accordion.Panel header={getLabel(32905, "常用条件")} className="custom-header">
                        <List>
                            <List.FormItem
                                extra={<Icon type="editor" size="xxs"/>}
                                label={getLabel(24986, "标题")}
                                line
                                noBorder
                                content={<InputItem
                                    placeholder={getLabel(83869, "请输入")}
                                    value={queryParams.scorename}
                                    onChange={val => onSearchChange({"scorename": val})}
                                />}
                            />
                        </List>
                        <List>
                            <List.FormItem
                                noBorder
                                content={
                                    <Select
                                        value={queryParams.type1}
                                        options={cicleData}
                                        label={getLabel(15386, "周期")}
                                        onChange={val => onSearchChange({"type1": val})}
                                    />}
                            />
                        </List>
                        <List>
                            <BrowserHrm
                                store={hrmBrowser}
                                isSingle={false}
                                hasAdvanceSerach
                                label={getLabel(30042, "人员")}
                                type={1}
                                onChange={(...arg) => {
                                    onSearchChange({hrmids: arg[0]})
                                    setState({hrmBrowserValue: arg[2]})
                                }}
                                valueArray={hrmBrowserValue}
                            />
                        </List>
                        <List className="border-none">
                            <List.FormItem
                                noBorder
                                line
                                content={
                                    <Select
                                        value={queryParams.includesub}
                                        options={includesubData}
                                        label={getLabel(33553, "分部")}
                                        onChange={val => onSearchChange({"includesub": val})}
                                    />
                                }
                            />
                        </List>
                        <List>
                            <Browser
                                store={subBrowser}
                                hasAdvanceSerach
                                label=" "
                                type={164}
                                tabs={[{
                                    "isSearch": false,
                                    "key": "2",
                                    "name": getLabel(18770, "按组织结构"),
                                    "selected": false,
                                    "showOrder": 0
                                }, {
                                    "dataParams": {"list": "1"},
                                    "isSearch": true,
                                    "key": "1",
                                    "name": getLabel(130619, '按列表'),
                                    "selected": false,
                                    "showOrder": 0
                                }]}
                                onChange={(...arg) => {
                                    onSearchChange({subcompanyids: arg[0]})
                                    setState({subBrowserValue: arg[2]})
                                }}
                                valueArray={subBrowserValue}
                            />
                        </List>
                        <List className="border-none">
                            <List.FormItem
                                noBorder
                                line
                                content={
                                    <Select
                                        value={queryParams.includedept}
                                        options={includedeptData}
                                        label={getLabel(27511, "部门")}
                                        onChange={val => onSearchChange({"includedept": val})}
                                    />
                                }
                            />
                        </List>
                        <List>
                            <Browser
                                store={deptBrowser}
                                hasAdvanceSerach
                                label=" "
                                type={4}
                                tabs={[{
                                    "isSearch": false,
                                    "key": "2",
                                    "name": getLabel(18770, "按组织结构"),
                                    "selected": false,
                                    "showOrder": 0
                                }, {
                                    "dataParams": {"list": "1"},
                                    "isSearch": true,
                                    "key": "1",
                                    "name": getLabel(130619, '按列表'),
                                    "selected": false,
                                    "showOrder": 0
                                }]}
                                onChange={(...arg) => {
                                    onSearchChange({departmentids: arg[0]})
                                    setState({deptBrowserValue: arg[2]})
                                }}
                                valueArray={deptBrowserValue}
                            />
                        </List>
                    </Accordion.Panel>
                </Accordion>
                <ButtonGroup data={this.getButton()}/>
            </div>
        )
    }

    getButton = () => {
        const {resetCondition, getTableDatas} = this.store;
        return [{
            key: "reset",
            text: getLabel(2022, "重置"),
            onClick: () => resetCondition(),
        }, {
            key: "search",
            text: getLabel(388113, "搜索"),
            onClick: () => {
                getTableDatas();
                this.props.history.go(-1)
            },
            type: "primary",
        }];
    }

}

